home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / CUSTOM.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  12.6 KB  |  533 lines

  1. /* ===================================================================
  2.  * FILE: CUSTOM.C
  3.  * ===================================================================
  4.  * DATE: December 9, 1992
  5.  * 
  6.  * DESCRIPTION: Fonts ACC
  7.  *
  8.  * This file handles the Custom dialog box.
  9.  *
  10.  * COMPILER: TURBO C Version 2.0
  11.  */
  12.  
  13.  
  14. /* INCLUDE FILES
  15.  * ===================================================================
  16.  */
  17. #include <sys\gemskel.h>
  18. #include <tos.h>
  19. #include <linea.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #include "country.h"
  24. #include "fonthead.h"
  25. #include "fonts.h"
  26. #include "mainstuf.h"
  27. #include "text.h"
  28. #include "fsmio.h"
  29. #include "mover.h"
  30. #include "front.h"
  31.  
  32.  
  33.  
  34. /* STRUCTURES
  35.  * ===================================================================
  36.  */
  37.  
  38.  
  39. /* EXTERN
  40.  * ===================================================================
  41.  */
  42. extern int AES_Version;
  43.  
  44.  
  45.  
  46. /* PROTOTYPES
  47.  * ===================================================================
  48.  */
  49. void    DoCustom( void );
  50. int    HandleCustom( int button, WORD *msg );
  51.  
  52. void    SetXFlags( int devnum );
  53. void    SetCustomDevice( int devnum, int draw );
  54. void    DoXInstall( void );
  55. void    DoXRemove( void );
  56. int    SearchDevicesForFont( FON_PTR curptr );
  57.  
  58.  
  59.  
  60. /* DEFINES
  61.  * ===================================================================
  62.  */
  63. #define ACTIVE           0
  64. #define INACTIVE       1
  65. #define CUSTOM_HEIGHT  6
  66. #define UNDO        0x6100
  67. #define FRONT_HEIGHT    14
  68. #define INACTIVE_HEIGHT    14
  69.  
  70.  
  71. /* GLOBALS
  72.  * ===================================================================
  73.  */
  74. DEV_PTR cur_device;
  75.  
  76. char DeviceNum[4];
  77. char DeviceName[15];
  78. FON_PTR IList, ILast;    /* Installed List */
  79. int ICount;
  80. FON_PTR AList, ALast;    /* Available List */
  81. int ACount;
  82. int APosition;
  83. int IPosition;
  84.  
  85. /* FUNCTIONS
  86.  * ===================================================================
  87.  */
  88.  
  89.  
  90. /* DoCustom()
  91.  * ===================================================================
  92.  */
  93. void
  94. DoCustom( void )
  95. {
  96.     Reset_Tree( ad_custom );
  97.  
  98.     /* Get the rest of the fonts if they haven't been loaded */
  99.     if( !Fonts_Loaded )
  100.     {
  101.       MF_Save();
  102.       Scan_Message( ad_scan, TRUE );    
  103.  
  104.       read_fonts( TRUE, FALSE );
  105.  
  106.       Scan_Message( ad_scan, FALSE );
  107.       MF_Restore();
  108.     }  
  109.  
  110.  
  111.     /* INitialize the device number and the device name */
  112.     cur_device = device_head;
  113.     if( cur_device )
  114.     {
  115.     /* Get the Device Number and Name */
  116.     sprintf( DeviceNum, "%d", DDEV( cur_device ));
  117.     TedText( XDEVNUM ) = DeviceNum;
  118.  
  119.     strcpy( DeviceName, drivers[ DNAME( cur_device ) ] );
  120.     TedText( XFNAME ) = DeviceName;
  121.     }
  122.  
  123.     Disable( XINSTALL );
  124.     Disable( XREMOVE );
  125.     NoExit( XINSTALL );
  126.     NoExit( XREMOVE );
  127.  
  128.     /* Set up the Installed and available bitmap fonts for devices */
  129.     SetCustomDevice( DDEV( cur_device ), FALSE );
  130.     Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  131. }
  132.  
  133.  
  134.  
  135. /* HandleCustom()
  136.  * ===================================================================
  137.  */
  138. int
  139. HandleCustom( int button, WORD *msg )
  140. {
  141.    int     quit;
  142.    MRETS   mk;
  143.    int     dclick;
  144.  
  145.    dclick = FALSE;
  146.    quit   = FALSE;
  147.  
  148.    
  149.    /* Handle Double-clicking of the objects */   
  150.    if( ( button != -1 ) && ( button & 0x8000 ) )
  151.    {
  152.       button &= 0x7FFF;
  153.       dclick = TRUE;
  154.    }
  155.    
  156.    switch( button )
  157.    {
  158.      case CUSTOMOK: Deselect( button );
  159.  
  160.             Reset_Tree( ad_options );            
  161.  
  162.             free_arena_links();
  163.             installed_count = build_list( &installed_list, &installed_last, ACTIVE );
  164.             available_count = build_list( &available_list, &available_last, INACTIVE );
  165.  
  166.             ClearFnodes( installed_list );
  167.             ClearFnodes( available_list );
  168. #if 0
  169.  
  170. THIS ISN'T NEEDED! THE RESET IS DONE WHEN WE RETURN FROM OPTIONS TO FRONT
  171.             /* RESET the SCROLLERS for the INSTALLED FONTS */
  172.             Reset_Tree( ad_front );            
  173.                     mover_setup( installed_list, installed_count,
  174.                          FBASE, FSLIDER, FUP, FDOWN,
  175.                    LINE0, LINE13, LINEBASE, 0, FRONT_HEIGHT );
  176.  
  177.  
  178.             /* RESET the SCROLLERS for the AVAILABLE FONTS */  
  179.             Reset_Tree( ad_front );            
  180.             mover_setup( available_list, available_count,
  181.                   IBASE, ISLIDER, IUP, IDOWN,
  182.                   ILINE0, ILINE13, ILINE, 0, INACTIVE_HEIGHT );
  183. #endif
  184.             Reset_Tree( ad_options );            
  185.             HideObj( OBASE );
  186.             Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  187.                  break;
  188.  
  189.      case XUP:        XSelect( tree, XUP );
  190.             do
  191.             {
  192.                if( DNEXT( cur_device ) )
  193.                {
  194.                cur_device = DNEXT( cur_device );
  195.  
  196.                /* Get the Device Number and Name */
  197.                sprintf( DeviceNum, "%d", DDEV( cur_device ));
  198.                TedText( XDEVNUM ) = DeviceNum;
  199.  
  200.                strcpy( DeviceName, drivers[ DNAME( cur_device ) ] );
  201.                TedText( XFNAME ) = DeviceName;
  202.  
  203.                RedrawObject( tree, XDEVNUM );
  204.                RedrawObject( tree, XFNAME );
  205.  
  206.                SetCustomDevice( DDEV( cur_device ), TRUE );
  207.  
  208.                        if( !IsDisabled( XINSTALL ) )
  209.                        ChangeButton( ad_custom, XINSTALL, FALSE );
  210.  
  211.                           if( !IsDisabled( XREMOVE ) )
  212.                        ChangeButton( ad_custom, XREMOVE, FALSE );
  213.  
  214.                Evnt_timer( 50L );
  215.                }
  216.                     Graf_mkstate( &mk );
  217.             }while( mk.buttons );
  218.             XDeselect( tree, XUP );
  219.             break;
  220.  
  221.      case XDOWN:    XSelect( tree, XDOWN );
  222.             do
  223.             {
  224.                if( DPREV( cur_device ) )
  225.                {
  226.                cur_device = DPREV( cur_device );
  227.  
  228.                /* Get the Device Number and Name */
  229.                sprintf( DeviceNum, "%d", DDEV( cur_device ));
  230.                TedText( XDEVNUM ) = DeviceNum;
  231.  
  232.                strcpy( DeviceName, drivers[ DNAME( cur_device ) ] );
  233.                TedText( XFNAME ) = DeviceName;
  234.  
  235.                RedrawObject( tree, XDEVNUM );
  236.                RedrawObject( tree, XFNAME );
  237.  
  238.                SetCustomDevice( DDEV( cur_device ), TRUE );
  239.  
  240.                        if( !IsDisabled( XINSTALL ) )
  241.                        ChangeButton( ad_custom, XINSTALL, FALSE );
  242.  
  243.                           if( !IsDisabled( XREMOVE ) )
  244.                        ChangeButton( ad_custom, XREMOVE, FALSE );
  245.  
  246.                Evnt_timer( 50L );
  247.                }
  248.                     Graf_mkstate( &mk );
  249.             }while( mk.buttons );
  250.             XDeselect( tree, XDOWN );
  251.                  break;
  252.  
  253.      case LLINE0:
  254.      case LLINE1:
  255.      case LLINE2:
  256.      case LLINE3:
  257.      case LLINE4:
  258.      case LLINE5:
  259.      case LUP:
  260.      case LDOWN:
  261.      case LBASE:
  262.      case LSLIDER:  /* Check if the mover hdptr is already this list's */
  263.             if( hdptr != IList )
  264.             {
  265.               APosition = Get_Findex( AList, Active_Slit[0] );
  266.               Undo_Fnodes( AList, ( FON_PTR )NULL );
  267.               mover_setup( IList, ICount, LBASE, LSLIDER, LUP, LDOWN,
  268.                     LLINE0, LLINE5, LLINE, IPosition, CUSTOM_HEIGHT );
  269.             }
  270.             mover_button( button, dclick );
  271.             IPosition = Get_Findex( IList, Active_Slit[0] );
  272.             break;
  273.  
  274.      case RLINE0:
  275.      case RLINE1:
  276.      case RLINE2:
  277.      case RLINE3:
  278.      case RLINE4:
  279.      case RLINE5:
  280.      case RUP:
  281.      case RDOWN:
  282.      case RBASE:
  283.      case RSLIDER:  /* Check first if the list is already at hdptr */
  284.             if( hdptr != AList )
  285.             {
  286.               IPosition = Get_Findex( IList, Active_Slit[0] );
  287.               Undo_Fnodes( IList, ( FON_PTR )NULL );
  288.               mover_setup( AList, ACount, RBASE, RSLIDER, RUP, RDOWN,
  289.                   RLINE0, RLINE5, RLINE, APosition, CUSTOM_HEIGHT );
  290.             }
  291.             mover_button( button, dclick );
  292.             APosition = Get_Findex( AList, Active_Slit[0] );
  293.             break;
  294.  
  295.  
  296.      case XINSTALL: DoXInstall();
  297.             XDeselect( tree, XINSTALL );
  298.  
  299.             break;
  300.  
  301.      case XREMOVE:  DoXRemove();
  302.             XDeselect( tree, XREMOVE );
  303.             break;
  304.  
  305.      default:     if( button == -1 )
  306.               {
  307.                 switch( msg[0] )
  308.                 {
  309.                   case WM_REDRAW: 
  310.                                break;
  311.                                    
  312.                   case AC_CLOSE:  quit = TRUE;
  313.                                break;
  314.                                        
  315.                   case WM_CLOSED: quit = TRUE;
  316.                      free_arena_links();
  317.                          installed_count = build_list( &installed_list, &installed_last, ACTIVE );
  318.                          available_count = build_list( &available_list, &available_last, INACTIVE );
  319.  
  320.                          ClearFnodes( installed_list );
  321.                          ClearFnodes( available_list );
  322.                   
  323.                                CloseWindow();
  324.                      break;
  325.  
  326.              case CT_KEY:    if( msg[3] == UNDO )
  327.                           {
  328.                         if( hdptr == IList )
  329.                           Undo_Fnodes( IList, ( FON_PTR )NULL );
  330.  
  331.                         if( hdptr == AList )
  332.                           Undo_Fnodes( AList, ( FON_PTR )NULL );
  333.                           }
  334.                           break;
  335.                   default:
  336.                           break;
  337.                 }
  338.               }
  339.               else
  340.               {
  341.              if( hdptr == IList )
  342.                 Undo_Fnodes( IList, ( FON_PTR )NULL );
  343.  
  344.                  if( hdptr == AList )
  345.                 Undo_Fnodes( AList, ( FON_PTR )NULL );
  346.               }
  347.               break;
  348.    }
  349.    return( quit );
  350.  
  351.  
  352. }
  353.  
  354.  
  355.  
  356. /* SetXFlags()
  357.  * ===================================================================
  358.  */
  359. void
  360. SetXFlags( int devnum )
  361. {
  362.     DEV_PTR curptr;
  363.     FON_PTR fonptr;
  364.     int     i;
  365.  
  366.     /* Find the current device */
  367.     curptr = find_device( devnum );
  368.  
  369.     /* Find and set to SELECTED, the fonts on the device */
  370.     if( curptr )
  371.     {
  372.       for( i = 0; i < DFCOUNT( curptr ); i++ )
  373.       {
  374.           fonptr = DFONT( curptr )[i];
  375.           
  376.       if( fonptr )
  377.           XFLAG( fonptr ) = TRUE;
  378.       }
  379.     }
  380. }
  381.  
  382.  
  383.  
  384. /* SetCustomDevice()
  385.  * ===================================================================
  386.  */
  387. void
  388. SetCustomDevice( int devnum, int draw )
  389. {
  390.     free_arena_links();
  391.     SetXFlags( devnum );
  392.  
  393.     IPosition = APosition = 0;
  394.     IList = ILast = ( FON_PTR )NULL;
  395.     AList = ALast = ( FON_PTR )NULL;
  396.     ICount = ACount = 0;
  397.  
  398.     ICount = BuildBitMapList( &IList, &ILast, ACTIVE );    
  399.     ACount = BuildBitMapList( &AList, &ALast, INACTIVE );    
  400.  
  401.     mover_setup( IList, ICount, LBASE, LSLIDER, LUP, LDOWN,
  402.          LLINE0, LLINE5, LLINE, 0, CUSTOM_HEIGHT );
  403.  
  404.     mover_setup( AList, ACount, RBASE, RSLIDER, RUP, RDOWN,
  405.          RLINE0, RLINE5, RLINE, 0, CUSTOM_HEIGHT );
  406.  
  407.     if( draw )
  408.     {
  409.         Objc_draw( tree, LLINE, MAX_DEPTH, NULL );
  410.     RedrawObject( tree, LBASE );
  411.  
  412.         Objc_draw( tree, RLINE, MAX_DEPTH, NULL );
  413.     RedrawObject( tree, RBASE );
  414.     }
  415. }
  416.  
  417.  
  418.  
  419. /* DoXInstall()
  420.  * ===================================================================
  421.  */
  422. void
  423. DoXInstall( void )
  424. {
  425.     FON_PTR curptr;
  426.     int     flag;
  427.     
  428.     if( IsChanged( AList ) )
  429.     {
  430.     sprintf( line_buf, alertc1, DDEV( cur_device ) );
  431.         if( form_alert( 1, line_buf  ) == 1 )
  432.     {
  433.         flag = FALSE;
  434.         curptr = AList;
  435.         while( curptr )
  436.         {
  437.         if( AFLAG( curptr ) )
  438.         {
  439.            flag = add_to_device( cur_device, curptr );
  440.            if( !flag )
  441.            {
  442.               form_alert( 1, alertc7 );
  443.               break;
  444.            }
  445.            
  446.            /* ADD THIS TO THE INSTALLED LIST!!!!!
  447.             * If it already hasn't been done
  448.             * NOTE: ONLY Device 1 - 10 
  449.             */
  450.            if( ( DDEV( cur_device ) >= 1 ) && ( DDEV( cur_device ) <= 10 ) )
  451.                 SEL( curptr ) = TRUE;
  452.         }   
  453.         curptr = FNEXT( curptr );
  454.         }
  455.         SetCustomDevice( DDEV( cur_device ), TRUE );
  456.             if( !IsDisabled( XINSTALL ) )
  457.                   ChangeButton( ad_custom, XINSTALL, FALSE );
  458.                   
  459.                /* No errors! */
  460.         if( flag )
  461.           SetChangeFlag();
  462.     }
  463.     }
  464. }
  465.  
  466.  
  467. /* DoXRemove()
  468.  * ===================================================================
  469.  */
  470. void
  471. DoXRemove( void )
  472. {
  473.     FON_PTR curptr;
  474.  
  475.     if( IsChanged( IList ) )
  476.     {
  477.     sprintf( line_buf, alertc2, DDEV( cur_device ) );
  478.         if( form_alert( 1, line_buf  ) == 1 )
  479.     {
  480.         curptr = IList;
  481.         while( curptr )
  482.         {
  483.         if( AFLAG( curptr ) )
  484.         {
  485.            remove_from_device( cur_device, curptr );
  486.            
  487.            /* Search devices 1-10, if they exist
  488.             * and see if this font 'curptr' is used
  489.             * still. If so, do nothing...
  490.             * if NOT, REMOVE IT -> SEL() = FALSE
  491.             */
  492.            if( !SearchDevicesForFont( curptr ))
  493.               SEL( curptr ) = FALSE;
  494.            
  495.         }   
  496.         curptr = FNEXT( curptr );
  497.         }
  498.         SetCustomDevice( DDEV( cur_device ), TRUE );
  499.               if( !IsDisabled( XREMOVE ) )
  500.               ChangeButton( ad_custom, XREMOVE, FALSE );
  501.             SetChangeFlag();
  502.     }
  503.     }
  504. }
  505.  
  506.  
  507.  
  508.  
  509. /* SearchDevicesForFont()
  510.  * ===================================================================
  511.  */
  512. int
  513. SearchDevicesForFont( FON_PTR curptr )
  514. {
  515.    int flag;
  516.    DEV_PTR cur_device;
  517.    
  518.    flag = FALSE;
  519.    
  520.    cur_device = device_head;
  521.    while( cur_device )
  522.    {
  523.         if(  ( DDEV( cur_device ) >= 1 ) && ( DDEV( cur_device ) <= 10 ) )
  524.         {
  525.             if( FindFontInDevice( cur_device, curptr ) )
  526.                flag = TRUE;
  527.         }
  528.         cur_device = DNEXT( cur_device );
  529.    }
  530.    return( flag );
  531. }
  532.  
  533.